﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ZYKTool;
using HQL;
using LongZhiJie;

public class Projectile : MonoBehaviour {

    public float speed;
    public float lifeTime;
    public float distance;
    public float damage;
    public LayerMask whatIsSolid;

    public GameObject destroyEffect;
    public EnumGun _enumGun;

    private void Start()
    {
        
        Invoke("DestroyProjectile", lifeTime);
        if(_enumGun==EnumGun.Gun3)
        {
            ZYKTool.Timer.ZYKTimerSystemTool.Instance.ZYKTimerAddTimerTask(() => { damage -= 1.5f; }, 0.1f);//散弹枪越远伤害越低
        }
    }
    int _中毒ID = -1;
    float _中毒额外伤害 = 0;
    private void Update()
    {
       
        RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, transform.up, distance, whatIsSolid);
        if (hitInfo.collider != null) {
            if (hitInfo.collider.CompareTag("Enemy")) {
                
                BossBase bossBase=hitInfo.collider.transform.GetOrAddComponent<BossBase>();
                if(bossBase._Is中毒&& _enumGun==EnumGun.Gun2)
                {
                    
                    if (_中毒ID==-1)
                    {
                        ZYKTool.Timer.ZYKTimerSystemTool.Instance.ZYKTimerAddTimerTask(() => { _中毒额外伤害 = 0; }, 1, 1);
                    }
                    else
                    {
                        _中毒额外伤害 += 2;
                        ZYKTool.Timer.ZYKTimerSystemTool.Instance.ZYKTimerReplaceTimeTask(_中毒ID,() => { _中毒额外伤害 = 0; }, 1, 1);
                    }

                    Debug.LogError(_中毒额外伤害);
                }
                bossBase.BossHunt(damage + _中毒额外伤害);
                //hitInfo.collider.GetComponent<Enemy>().TakeDamage(damage);
            }
            DestroyProjectile();
        }


        transform.Translate(Vector2.up * speed * Time.deltaTime);
    }

    void DestroyProjectile() {
        Destroy(Instantiate(destroyEffect, transform.position, Quaternion.identity),1);
        Destroy(gameObject);
    }


}
